<template>
  <div>
    <v-dialog title="接收" :show.sync="dialogVisible" @beforeClose="beforeClose" width="800px">
      <div>
        <p>注：确认合同准确无误，点击审核通过生成合同应付；如果合同有误，点击退回租赁合同。</p>
      </div>
      <span slot="foot">
        <el-button size="small" @click="returned">退回合同</el-button>
        <el-button size="small" @click="dialogVisible = false">取消</el-button>
        <el-button size="small" type="primary" @click="receive">确认接收</el-button>
      </span>
    </v-dialog>
  </div>
</template>

<script>
import { check, addReceive } from '@/views/wy-rent/api/rent-contract-acceptance.js'
import BaseLoad from '@/assets/vue-mixin/BaseLoad'
export default {
  mixins: [BaseLoad],
  data () {
    return {
      dialogVisible: false,
      form: {
        remarks: "",
        busId: "",
        category: 2,
      },
    }
  },
  methods: {
    show (item) {
      this.dialogVisible = true
      //setTimeout(() => {
      if (item) {
        this.form.busId = item.rentContractId
        //alert(this.form.busId);
      }
      //}, 200)
    },
    commit () {
      this.$refs.editForm.validate(valid => {
      })
    },
    beforeUpload () {
      this.loadAction('请稍等...')
    },
    returned () {
      this.$prompt('请填写退回原因', '退回原因', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /\S/,
        inputErrorMessage: '退回原因不能为空'
      }).then(({ value }) => {
        this.form.remarks = value
        const obj = {
          approvalResult: '03',
          opinion: '退回'
        }
        addReceive({ ...this.form, ...obj }).then(resp => {
          if (resp.data.data) {
            this.$message({
              type: 'success',
              message: '合同已退回经营部！'
            });
            this.dialogVisible = false;
            this.$emit('resetList')
            this.$emit('getTabListData')
            this.$forceUpdate()
          } else {
            this.err('操作失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        });
      });
    },
    receive () {
      const obj = {
        approvalResult: '02',
        opinion: '同意'
      }
      addReceive({ ...this.form, ...obj }).then(resp => {
        if (resp.data.data) {
          this.$message({
            type: 'success',
            message: '合同已接收！'
          });
          this.dialogVisible = false;
          this.$emit('resetList')
          this.$emit('clickCheck')
          this.$emit('getTabListData')
        } else {
          this.err('操作失败')
        }
      })
    },
    beforeClose (done) {
      done();
    }
  }
}
</script>

<style scoped lang='scss'>
@include data-title();

@include info-list(2);
@include formWrap(3);
</style>
